package com.assets.asset.annotation.aop;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.assets.asset.mapper.TReturnMapper;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class ReturnComIdAop {

    @Autowired
    private TReturnMapper tReturnMapper;


    @Around("@annotation(com.assets.asset.annotation.ReturnComId)")
//    public void around(JoinPoint point) throws Throwable {
    public Object around(ProceedingJoinPoint point) throws Throwable {


        //获取当前
//        Object[] args = joinPoint.getArgs();
        Object[] args = point.getArgs();

        Object result = point.proceed(args);

        String toJSONString = JSON.toJSONString(args);
        System.out.println("toJSONString = " + toJSONString);


        String s = toJSONString.replace("]", "");
        String replace = s.replace("[", "");
        System.out.println(replace);

        JSONObject jsonObject = JSON.parseObject(replace);
        String assetCode = jsonObject.getString("assetCode");

        //转ID
        tReturnMapper.updateCom(assetCode);

        return result;
    }
}
